package com.xms.schema.service.stringmap;

import com.xms.core.exception.XmsException;
import com.xms.datacore.service.CreaterService;
import com.xms.schema.entity.StringMap;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.Collection;

/**
 * <p>
 * StringMapCreaterService
 * </p>
 *
 * @author migo
 * @since 2021/9/8
 */
@CacheConfig(cacheNames = "schema.stringmap", keyGenerator = "CacheKeyGenerator")
@Service
public class StringMapCreaterService extends CreaterService<StringMap> implements IStringMapCreaterService {

    @CacheEvict(allEntries = true, condition = "#result == true")
    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean create(StringMap entity) throws SQLException, XmsException {
        return super.save(entity);
    }

    @CacheEvict(allEntries = true, condition = "#result == true")
    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean createMany(Collection<StringMap> entityList) throws SQLException, XmsException {
        for (StringMap entity : entityList){
            super.save(entity);
        }
        return true;
    }
}
